

<!DOCTYPE html>
<html  lang="en">
<head>
  <meta charset="utf-8">
  <title>设置我的资料</title>
  <meta name="renderer" content="webkit">
  <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
  <meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
  <link rel="stylesheet" href="../../static//layuiadmin/layui/css/layui.css" media="all">
  <link rel="stylesheet" href="../../static/layuiadmin/style/admin.css" media="all">
</head>
<body>

  <div class="layui-fluid">
    <div class="layui-row layui-col-space15">
      <div class="layui-col-md12">
        <div class="layui-card">
          <div class="layui-card-header">设置我的资料</div>
          <div class="layui-card-body" pad15>

            <div class="layui-form" lay-filter="">
              <div class="layui-form-item">
                <label class="layui-form-label">我的角色</label>
                <div class="layui-input-inline" >
                  <input type="text" id="myRole" readonly class="layui-input">
                </div>
                <div class="layui-form-mid layui-word-aux">当前角色不可更改为其它角色</div>
              </div>
              <div class="layui-form-item">
                <label class="layui-form-label" >登录名</label>
                <div class="layui-input-inline">
                  <input type="text"  id="loginName"  readonly class="layui-input">
                </div>
                <div class="layui-form-mid layui-word-aux">不可修改。于后台登入名</div>
              </div>
              <div class="layui-form-item">
                <label class="layui-form-label" >昵称</label>
                <div class="layui-input-inline">
                  <input type="text" name="nickname" id="adminName" lay-verify="nickname" autocomplete="off" placeholder="请输入昵称" class="layui-input">
                </div>
              </div>
              <div class="layui-form-item">
                <label class="layui-form-label">性别</label>
                <div class="layui-input-block">
                  <input type="radio" name="gender" value="男" title="男" checked>
                  <input type="radio" name="gender" value="女" title="女" >
                </div>
              </div>
              <div class="layui-form-item">
                <label class="layui-form-label">手机</label>
                <div class="layui-input-inline">
                  <input type="text" id="cellphone"  lay-verify="phone" autocomplete="off" class="layui-input">
                </div>
              </div>
              <div class="layui-form-item">
                <label class="layui-form-label">邮箱</label>
                <div class="layui-input-inline">
                  <input type="text" id="email"  lay-verify="email" autocomplete="off" class="layui-input">
                </div>
              </div>
              <div class="layui-form-item layui-form-text">
                <label class="layui-form-label">备注</label>
                <div class="layui-input-block">
                  <textarea name="remarks" id="remarks" placeholder="请输入内容" class="layui-textarea"></textarea>
                </div>
              </div>
              <div class="layui-form-item">
                <div class="layui-input-block">
                  <button class="layui-btn" lay-submit onclick="updateAdmin()">确认修改</button>
                  <button type="reset" class="layui-btn layui-btn-primary" onclick="cancel()">重新填写</button>
                </div>
              </div>
            </div>

          </div>
        </div>
      </div>
    </div>
  </div>

  <script src="../../static/layuiadmin/layui/layui.js"></script>
  <script>
  layui.config({
    base: '../../static/layuiadmin/' //静态资源所在路径
  }).extend({
    index: 'lib/index' //主入口模块
  }).use(['index', 'set']);
  </script>

  <script src="../../static/js/jquery.min.js"></script>
  <script>
    $(document).ready(function find(){
      $.ajax({
        url:"../../admin/find",
        type:"GET",
        success:function (res){
          $("#loginName").val(res.data.loginName);
          $("#adminName").val(res.data.adminName);
          $("#myRole").val(res.data.roleBean.roleName);
          $("#remarks").val(res.data.adminDesc);
          $("#cellphone").val(res.data.telephone);
          $("#email").val(res.data.email);
          if(res.data.gender === 1){
            $("input[name='gender'][value='男']").prop("checked",true);
          }else{
            $("input[name='gender'][value='女']").prop("checked",true)
          }
          console.info(res)
        },error:function (){
          alert("出错啦……")
        }
      })
    });
    //修改请求
    function updateAdmin() {
      let adminName = $("#adminName").val();
      let loginName = $("#loginName").val();
      let adminDesc = $("#remarks").val();
      let telephone = $("#cellphone").val();
      let email = $("#email").val();
      let gender=$("input[name='gender']:checked").val();
      if(gender==='男'){
        gender = 1
      }else {
        gender = 0
      }
      if(adminName===''||telephone===''||email===''){
        alert("必填项不能为空")
        return ;
      }
      $.ajax({
        url:"../../admin/update",
        type:"POST",
        data:{
          loginName:loginName,
          adminName:adminName,
          adminDesc:adminDesc,
          telephone:telephone,
          email:email,
          gender:gender
        },success:function (res) {
          if(res.code===200){
            alert(res.message)
          }else{
            alert(res.message)
          }
        }
      })
    }
    function cancel() {
      if (confirm("确定要重新填写吗，将会清空当前信息")){
        $("#adminName").val("");
        $("#remarks").val("");
        $("#cellphone").val("");
        $("#email").val("");
      }
    }

  </script>




</body>
</html>
